package com.zy.ivideo.controller;

import com.zy.ivideo.entity.AccountEntity;
import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.service.AccountService;
import com.zy.ivideo.token.UserToken;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
@Api(value = "账户模块API接口", description = "该模块提供账户模块服务", tags = "账户模块")
public class AccountController {
    @Autowired
    AccountService service;

    /**
     * 添加 账户 信息
     * @param entity
     * @return
     */
    @UserToken
    @ApiOperation(value = "添加账户信息", notes = "添加账户信息", httpMethod = "POST")
    @PostMapping("/addAccount")
    public ResponseEntity<AccountEntity> addAccount(@RequestBody
                                                        @ApiParam(value = "账户实体", name = "entity", required = true)
                                                                AccountEntity entity){
        return service.addAccount(entity);
    }

    /**
     * 根据id删除账户信息
     * @param id
     * @return
     */
    @UserToken
    @ApiOperation(value = "根据id删除账户信息", notes = "根据id删除账户信息", httpMethod = "DELETE")
    @DeleteMapping("/removeAccountById")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "账户id", required = true),
    })
    public ResponseEntity<Boolean> removeAccountById(Long id){
        return service.removeAccountById(id);
    }

    /**
     * 根据账号id获取对应账户信息
     * @param id
     * @return
     */
    @UserToken
    @ApiOperation(value = "根据账号id获取对应账户信息", notes = "根据账号id获取对应账户信息", httpMethod = "GET")
    @GetMapping("/findAccountById")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "账户id", required = true),
    })
    public ResponseEntity<AccountEntity> findAccountById(Long id){
        return service.findAccountById(id);
    }

    /**
     * 根据用户id获取对应账户信息
     * @param userid
     * @return
     */
    @UserToken
    @ApiOperation(value = "根据用户id获取对应账户信息", notes = "根据用户id获取对应账户信息", httpMethod = "GET")
    @GetMapping("/findAccountByUserId")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "userid", value = "用户id", required = true),
    })
    public ResponseEntity<AccountEntity> findAccountByUserId(Long userid){
        return service.findAccountByUserId(userid);
    }

    /**
     * 修改账户信息
     * @param entity
     * @return
     */
    @UserToken
    @ApiOperation(value = "修改账户信息", notes = "修改账户信息", httpMethod = "PUT")
    @PutMapping("/modifyAccount")
    public ResponseEntity<AccountEntity> modifyAccount(@RequestBody
                                                           @ApiParam(value = "账户实体", name = "entity", required = true)
                                                                   AccountEntity entity){
        return service.modifyAccount(entity);
    }

    /**
     * 修改支付宝账号
     * @param id
     * @param zfb
     * @return
     */
    @UserToken
    @ApiOperation(value = "修改支付宝账号", notes = "修改支付宝账号", httpMethod = "PUT")
    @PutMapping("/modifyZFB")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "账户id", required = true),
            @ApiImplicitParam(dataType = "String", name = "zfb", value = "支付宝账号", required = true),
    })
    public ResponseEntity<Boolean> modifyZFB(Long id,String zfb){
        return service.modifyZFB(id,zfb);
    }


    /**
     * 修改微信账号信息
     * @param id
     * @param wx
     * @return
     */
    @UserToken
    @ApiOperation(value = "修改微信账号信息", notes = "修改微信账号信息", httpMethod = "PUT")
    @PutMapping("/modifyWX")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "账户id", required = true),
            @ApiImplicitParam(dataType = "String", name = "wx", value = "微信账号", required = true),
    })
    public ResponseEntity<Boolean> modifyWX(Long id,String wx){
        return service.modifyWX(id,wx);
    }

    /**
     * 修改账户金额
     * @param id
     * @param nm
     * @return
     */
    @UserToken
    @ApiOperation(value = "修改账户金额", notes = "修改账户金额", httpMethod = "PUT")
    @PutMapping("/modifyAccountAmount")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "账户id", required = true),
            @ApiImplicitParam(dataType = "String", name = "nm", value = "金额", required = true),
    })
    public ResponseEntity<Boolean> modifyAccountAmount(Long id,double nm){
        return service.modifyAccountAmount(id,nm);
    }

    /**
     * 修改金币余额
     * @param id
     * @param nm
     * @return
     */
    @UserToken
    @ApiOperation(value = "修改金币余额", notes = "修改金币余额", httpMethod = "PUT")
    @PutMapping("/modifyCoinAmount")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "账户id", required = true),
            @ApiImplicitParam(dataType = "String", name = "nm", value = "金额", required = true),
    })
    public ResponseEntity<Boolean> modifyCoinAmount(Long id,double nm){
        return service.modifyCoinAmount(id,nm);
    }
}
